<?php
namespace app\admin\controller;

use app\common\model\Userfeedbacks as UserfeedbacksModel;
use app\common\controller\AdminBase;
use think\Db;
use think\Session;

class Userfeedbacks extends AdminBase
{
	protected $userfeedbacks_model;

	protected function _initialize()
	{
		parent::_initialize();
		$this->userfeedbacks_model = new UserfeedbacksModel();
	}

	public function index($keyword = '', $page = 1)
	{
		$map = [];
		if($keyword){
			$map['userName|userPhone'] = ['like' , '%{$keyword}%'];
		}
		$userfeedbacks_list = $this->userfeedbacks_model->where($map)->order('id DESC')->paginate(15,false,['page' => $page]);

		return $this->fetch('index',['userfeedbacks_list'=>$userfeedbacks_list,'keyword'=>$keyword]);
	}

	public function reading($id)
	{
		$userfeedbacks = $this->userfeedbacks_model->find($id);
		$userfeedbacks->reading = '1';
		$userfeedbacks->readingDate = date('Y-m-d H:i:s',time());
		$userfeedbacks->readingMan = Session::get('admin_name');
		$userfeedbacks->save();

		return $this->fetch('reading',['userfeedbacks' => $userfeedbacks]);
	}

	public function delete($id = 0, $ids = [])
	{
		$id = $ids ? array_merge($ids) : $id;
		if($id){
			if($this->userfeedbacks_model->destroy($id)){
				return $this->success('删除成功');
			}else{
				return $this->error('删除失败');
			}
		}else{
			return $this->error('请选择需要删除的内容');
		}
	}
}